#include"Inspector.h"
#include<imgui\imgui.h>
using namespace ECS;
using namespace SYSTEM;
using namespace Component;

struct  Inspector::Impl
{
	Entity* selected;
	
	void Inspector()
	{
		if (selected == nullptr)
			return;
		
		auto&sg = selected->get<SceneGraphComp>();
		if (sg.isValid()&&ImGui::CollapsingHeader("Info") )
		{
			ImGui::InputText("name", sg->name.data(), 20);
		}

		auto& cam = selected->get<CameraComp>();
		if (cam.isValid() && ImGui::CollapsingHeader("Camera"))
		{
			ImGui::InputFloat("FOV",&cam->FOV);
		}
	}
};
SYSTEM::Inspector::Inspector()
{
	mpImpl = std::make_unique<Inspector::Impl>();
}

void SYSTEM::Inspector::tick(ECS::World* world, float deltaTime)
{
	ImGui::Begin("Inspector");
	
	mpImpl->Inspector();

	ImGui::End();
}


void SYSTEM::Inspector::receive(ECS::World* world, const EVENT::EditorSelected& event)
{
	mpImpl->selected = event.Selected;
}